﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucPost.ascx.cs" Inherits="PromotionApp.UserControl.ucPost" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<table class="editor" cellpadding="0" cellspacing="0" width="100%">    
    <tr id="trTopicSeparator" runat="server" style="height:10px;">
        <td colspan="2"></td>
    </tr>
    <tr id="trTopic" runat="server">
        <td valign="top" align="right" style="width:120px;">
            <label>Topic  :</label>
        </td>
        <td valign="top" align="left" style="width:760px;">
            <asp:TextBox ID="tbxTopic" runat="server" Width="760"></asp:TextBox>                        
        </td>       
    </tr>
    <tr style="height:10px;">
        <td colspan="2"></td>
    </tr>
    <tr>
        <td valign="top" align="right" style="width:120px;">
            <label>Message  :</label>
        </td>
        <td valign="top" align="left" style="width:760px;">                       
            <CKEditor:CKEditorControl ID="CKEditor1" runat="server" Width="778px"></CKEditor:CKEditorControl>                        
            <span style="color:Red;">*.jpg, *.png or *.gif only and file size must not exceed 200 kb.</span>
        </td>        
    </tr>
    <tr style="height:10px;">
        <td colspan="3"></td>
    </tr>
    <tr>
        <td valign="top" align="right" style="width:120px;">
            <label>Image  :</label>
        </td>
        <td valign="top" align="left" style="width:760px;">            
            <asp:FileUpload ID="fulImage" Width="500" Border-width="0" runat="server" />
        </td>       
    </tr>    
    <tr style="height:10px;">
        <td colspan="2"></td>
    </tr>
    <tr>
        <td valign="top" align="right" style="width:120px;">            
        </td>
        <td valign="top" align="left" style="width:760px;">
            <asp:Button ID="btnPost" runat="server" Text="Post" onclick="btnPost_Click" 
                ValidationGroup="PostTopic" OnClientClick="return ValidatePostedMessage();" />
            &nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" 
                CausesValidation="False" onclick="btnCancel_Click" />                
        </td>        
    </tr>
    <tr style="height:10px;">
        <td colspan="2"></td>
    </tr>  
</table>

<script language="javascript" type="text/javascript">
    function ValidatePostedMessage() {
        var isError = false;
        var errorMessage = "";
        var topic = "topic";
        var message = CKEDITOR.instances.<%= this.CKEditor1.ClientID%>.getData();                

        if ("<%=this.IsTopic %>" == "True") {
            topic = document.getElementById("<%=this.tbxTopic.ClientID %>").value;
        }

        if (topic == "") {
            isError = true;
            errorMessage = "Topic cannot be blank.";
        }

        if (message == "") {
            isError = true;
            errorMessage += "\r\nMessage cannot be blank.";
        }

        if (isError) {
            alert(errorMessage);
            return false;
        }
        
        return true;
    }
</script>